<?php
function bzg_general_control() {
	global $wpdb;
	echo '<link rel="stylesheet" href="' . get_theme_file_uri('/assets/css/admin.css') . '" type="text/css" media="all">';
	echo '<div class="mywrap">';
	if(!empty($_POST)) {
		$data = array();
		foreach($_POST as $key=>$val) {
			$val = 'analytics_code' == $key ? esc_html(stripslashes($val)) : sanitize_text_field($val);
			update_option(sanitize_key($key), $val);
		}
		echo '<div class="notice is-dismissible updated">设置保存成功！</div>';
	}

	$hicolor = get_option('hicolor', 'red');
	$carousel_type = get_option('carousel_type', 'carousel-fade');
?>

<form class="entry" method="post" action="<?php echo admin_url('admin.php?page=general'); ?>">
	<h2>主题设置</h2>
	<table class="form-table">
		<tr>
			<th scope="row"><label for="hicolor">配色方案</label></th>
			<td id="hicolor">
				<?php
					$colors = array('red', 'blue', 'green', 'cyan', 'violet');
					foreach($colors as $c) {
						$actived = $c == $hicolor ? ' active' : '';
						echo '<span class="' . $c . $actived . '"><span></span></span>';
					}
				?>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="carousel-type">轮播方式</label></th>
			<td>
				<select id="carousel-type" name="carousel_type">
					<?php
						$carouseltypes = array(
							'carousel-fade' => '淡入淡出',
							'carousel-vertical' => '上下滚动',
							'carousel-horizontal' => '左右滚动',
						);
						foreach($carouseltypes as $key=>$val) {
							$selected = $key == $carousel_type ? ' selected' : '';
							echo '<option value="' . $key . '"' . $selected . '>' . $val . '</option>';
						}
					?>
				</select>
				<p class="description">添加轮播图片<a href="<?php echo admin_url('admin.php?page=slides'); ?>">点击这里</a></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="home-title">首页标题</label></th>
			<td>
				<input id="home-title" name="home_title" class="regular-text code" type="text" value="<?php echo get_option('home_title'); ?>">
				<p class="description">网站首页标题Title标签的内容</p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="home-description">网站描述</label></th>
			<td>
				<textarea id="home-description" name="home_description" class="regular-text code" rows="3"><?php echo get_option('home_description'); ?></textarea>
				<p class="description">网站首页描述标签Description的内容</p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="icp-num">ICP备案号</label></th>
			<td>
				<input id="icp-num" name="icp_num" class="regular-text code" type="text" value="<?php echo get_option('icp_num'); ?>">
				<p class="description">工信部官网：<a href="http://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer nofollow">http://beian.miit.gov.cn/</a></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="gongan-num">公安部备案号</label></th>
			<td>
				<input id="gongan-num" name="gongan_num" class="regular-text code" type="text" value="<?php echo get_option('gongan_num'); ?>">
				<p class="description">公安部备案官网：<a href="http://www.beian.gov.cn/" target="_blank" rel="noopener noreferrer nofollow">http://www.beian.gov.cn/</a></p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="analytics-code">统计代码</label></th>
			<td>
				<textarea id="analytics-code" name="analytics_code" class="regular-text code" rows="3"><?php echo get_option('analytics_code'); ?></textarea>
				<p class="description">网站统计代码，将在每个页面的页脚输出</p>
			</td>
		</tr>
	</table>
	<p class="submit">
		<input type="submit" class="button-primary" value="保存设置">
		<input id="hicolor-input" type="hidden" name="hicolor" value="<?php echo $hicolor; ?>">
	</p>
</form>

<script type="text/javascript">
jQuery(document).ready(function() {
	jQuery('#hicolor > span').click(function() {
		var elm = jQuery(this);
		if(elm.hasClass('active')) return;
		jQuery('#hicolor-input').val(elm.attr('class'));
		elm.addClass('active').siblings().removeClass('active');
	});
});
</script>
</div>
<?php
}
?>
